package HttpPages;

import java.util.logging.Level;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;

import Database.Database;
import Logger.AppLogger;
import Objects.PendingMessage;

@Path("/recieveTextMessage")
public class recieveTextMessage 
{
	//-----------------------------------http methods--------------------------------

	// This method is called if TEXT_PLAIN is request
	@POST
	@Consumes(MediaType.TEXT_PLAIN)
	public String openConnectionRequest(@FormParam("my_android_id") String my_android_id,
			@FormParam("message_id") String message_id)
	{
		AppLogger.write(Level.INFO, "Recieving Request was recieved!");

		//finding in the database the requested message
		PendingMessage message = Database.getInstance().getPendingMessage(Integer.parseInt(message_id));

		if(message == null)
		{
			System.out.println("message was not found!");
			return "message was not found!";
		}
				
		if(!my_android_id.equals(message.get_to_android_id()))
		{
			return "You are not authorized!";
		}
		
		return message.get_from_android_id() + "_" + message.get_message_content();
	}


}
